package com.me.hippy.sdk.demo

import android.graphics.drawable.ClipDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import android.view.Gravity
import android.widget.ProgressBar
import androidx.appcompat.app.AppCompatActivity
import com.me.hippy.sdk.R
import kotlinx.android.synthetic.main.activity_seekbar_style.*

class SeekbarStyleDemoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_seekbar_style)

        seekbar.hiProgressDrawable(0xffaaaaaa.toInt(), 0xffffffff.toInt(), 0xffFF1493.toInt())
    }
}

/**
 * 设置ProgressBar进度条样式
 */
fun ProgressBar.hiProgressDrawable(
    backgroundColor: Int, secondaryProgressColor: Int,
    progressColor: Int
) {
    //设置Seekbar的样式
    val bgClipDrawable =
        ClipDrawable(ColorDrawable(backgroundColor), Gravity.LEFT, ClipDrawable.HORIZONTAL)
    bgClipDrawable.level = 10000
    val secondProgressClip =
        ClipDrawable(ColorDrawable(secondaryProgressColor), Gravity.LEFT, ClipDrawable.HORIZONTAL)
    val progressClip =
        ClipDrawable(ColorDrawable(progressColor), Gravity.LEFT, ClipDrawable.HORIZONTAL)
    val progressDrawables = arrayOf(bgClipDrawable, secondProgressClip, progressClip)
    val progressLayerDrawable = LayerDrawable(progressDrawables)
    progressLayerDrawable.setId(0, android.R.id.background)
    progressLayerDrawable.setId(1, android.R.id.secondaryProgress)
    progressLayerDrawable.setId(2, android.R.id.progress)
    this.progressDrawable = progressLayerDrawable
}